#include <stdio.h>
#include <stdlib.h>

#include "bdata.h"

BTData btdata_init (Key key) {
    BTData data;

    if ((data = (BTData) malloc (sizeof (struct _btdata_elmt)))
            == NULL) {
        fprintf (stderr, "btdata_init: failed to allocate %s\n", key);
        return NULL;
    }

    data->key = key;
    data->freq_in = 0;
    data->freq_out = 0;

    return data;
}

int btdata_free (BTData data) {
    int diff;

    diff = data->freq_in - data->freq_out;
    free (data);

    return diff;
}

int btdata_compare_keys (Key kstatic, Key kdynamic) {
    /* For the time being we simply use a wrapper for
     * strcmp - later we will make this case-insensitive. */
    return strcmp (kstatic, kdynamic);
}

void btdata_inc_freq (BTData data, FREQ freq) {
    switch (freq)
    {
    case FREQ_IN:
        data->freq_in++;
        return;
    case FREQ_OUT:
        data->freq_out++;
    }

    return;
}
